<template>
  <div>
    <el-dialog
      width="600px"
      :title="$t('更新推荐库存')"
      destroy-on-close
      append-to-body
      :visible.sync="show"
      :before-close="cancel"
    >
      <el-form @submit.native.prevent ref="formRef" :model="form" size="small" :rules="rules" label-width="160px">
        <el-form-item :label="$t('选择推荐库存的参考销量')" prop="type">
          <el-select style="width: 100%" v-model="form.type" :placeholder="$t('请选择')">
            <!-- type: 1周销量 2月销量 3总销量 -->
            <el-option :label="$t('周销量')" :value="1" />
            <el-option :label="$t('月销量')" :value="2" />
            <el-option :label="$t('总销量')" :value="3" />
          </el-select>
        </el-form-item>
      </el-form>
      <el-alert :title="$t('确定后会生成推荐库存的推导过程')" type="error" :closable="false" effect="dark" />
      <div slot="footer">
        <el-button @click="handleSubmit" type="primary">{{ $t('确认') }}</el-button>
        <el-button @click="cancel">{{ $t('关闭') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      // 表单参数
      form: {
        type: '',
      },
      // 表单校验
      rules: {
        type: [{ required: true, message: this.$t('请选择'), trigger: 'blur' }],
      },
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        Object.keys(this.form).forEach((key) => (this.form[key] = ''))
      }
    },
  },
  methods: {
    getList() {},

    handleSubmit() {
      this.$refs['formRef'].validate(async (valid) => {
        if (valid) {
          await this.download(
            'distribution/skuShop/computeRecommendStock',
            {
              ...this.form,
            },
            `computeRecommendStock_${new Date().getTime()}.xlsx`,
          )
          this.cancel()
        }
      })
    },
    cancel() {
      this.$emit('getList')
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss"></style>
